package capricornus.components.utils.window
{
	import capricornus.components.label.Label;
	
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;

	public class WindowUtils
	{
		/**
		 * 创建窗口 
		 * @param w
		 * @param h
		 * @return 
		 * 
		 */		
		public static function createWindow( w:int, h:int, strTitle:String="提示" ):Sprite
		{
			var s:Sprite = new Sprite();
			
			var shape:Shape = new Shape();
			shape.name = "back";
			shape.graphics.beginFill(0,0);
			shape.graphics.drawRect( 0, 0, w, h );
			shape.graphics.endFill();
			shape.cacheAsBitmap = true;
			s.addChild( shape );
			
			var title:Sprite = new WindotTitlePanel();
			title.name = "btndrag";
			title.width = w;
			s.addChild( title );
			
			var label:Label = new Label();
			label.name = "txtTitle";
			label.horizontalCenter = true;
			label.textColor = 0xFFCC66;
			label.mouseChildren = false;
			label.mouseEnabled = false;
			label.text = strTitle;
			label.x = int(w/2);
			label.y = (title.height-label.height)/2 >>0;
			s.addChild( label );
			
			var client:Sprite = new WindowClientPanel();
			client.width = w;
			client.height = h - title.height;
			client.y = title.height;
			s.addChild( client );
			
			var btn:SimpleButton = new WindowClosePanel();
			btn.name = "btnclose";
			btn.x = w - btn.width/2 - 2;
			btn.y = int((title.height)/2);
			s.addChild( btn );
			
			return s;
		}
	}
}